---
- hosts: masters
  remote_user: ubuntu
  become: yes
  become_method: sudo
  become_user: root
  gather_facts: yes
  connection: ssh
  
  tasks:
   - name: Add helm key
     ansible.builtin.apt_key:
       url: https://baltocdn.com/helm/signing.asc
       state: present 

   - name: Install apt-transport-https
     apt: 
       name:
         - apt-transport-https
       state: present

   - name: Add specified repository into sources list using specified filename
     ansible.builtin.apt_repository:
       repo: deb https://baltocdn.com/helm/stable/debian/ all main
       state: present
       filename: helm-stable-debian

   - name: Install helm
     apt: 
       name:
         - helm
       state: present

   - name: "Add helm repo bitnami"
     kubernetes.core.helm_repository: 
       name: bitnami
       repo_url: "https://charts.bitnami.com/bitnami"
      
   - name: "Add helm repo metallb"
     kubernetes.core.helm_repository: 
       name: metallb
       repo_url: "https://metallb.github.io/metallb"
      
   - name: Create a metellb k8s namespace
     kubernetes.core.k8s:
       name: metellb
       api_version: v1
       kind: Namespace
       state: present  

   - name: "Install MetalLB Chart"
     kubernetes.core.helm: 
       chart_ref: metallb/metallb
       name: metallb
       release_namespace: metallb
       values:
          configInline:
            address-pools:
            - name: default
              protocol: layer2
              addresses:
              - 192.168.1.112/30
      
